package com.platform.jpa.dao.other;

import java.util.ArrayList;
import java.util.List;

public class Condition {
    private String name;
    private Operation op;
    private  Object value;
    private boolean not = false;

    public Condition(String name, Operation op, Object value, boolean not) {
        setName(name);
        setOp(op);
        setValue(value);
        setNot(not);
    }

    public Condition(String name, Operation op, Object value) {
        this(name, op, value, false);
    }

    public Condition(Operation op) {
        this(null, op, null, false);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Operation getOp() {
        return op;
    }

    public void setOp(Operation op) {
        this.op = op;
    }

    public Object getValue() {
        return value;
    }

    public void setValue(Object value) {
        this.value = value;
    }

    public boolean isNot() {
        return not;
    }

    public void setNot(boolean not) {
        this.not = not;
    }


    public static class Builder {
        private List<Condition> fields = new ArrayList<>();
        public Builder add(String name, Operation op, Object value, boolean not) {
            fields.add(new Condition(name, op, value, not));
            return this;
        }
        public Builder add(String name, Operation op, Object value) {
            this.add(name, op, value, false);
            return this;
        }
        public List<Condition> build() {
            return fields == null || fields.isEmpty() ? null : fields;
        }
    }
}
